package cn.caskm.souvenirshopsystem.controller.admin;

import cn.caskm.souvenirshopsystem.domain.Result;
import cn.caskm.souvenirshopsystem.domain.dto.PageDTO;
import cn.caskm.souvenirshopsystem.domain.po.Announcement;
import cn.caskm.souvenirshopsystem.domain.query.AnnouncementQuery;
import cn.caskm.souvenirshopsystem.domain.vo.AnnouncementVO;
import cn.caskm.souvenirshopsystem.service.AnnouncementService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/announcement")
@RequiredArgsConstructor
public class AdminAnnouncementController {

    private final AnnouncementService announcementService;

    @GetMapping("/page")
    public Result<PageDTO<AnnouncementVO>> page(AnnouncementQuery query) {
        return announcementService.page(query);
    }

    @GetMapping("/detail/{announcementId}")
    public Result<AnnouncementVO> detail(@PathVariable("announcementId") Integer announcementId) {
        return announcementService.detail(announcementId);
    }

    @PostMapping("/publish")
    public Result<Void> publishAnnouncement(@RequestBody Announcement announcement) {
        return announcementService.publishAnnouncement(announcement);
    }

    @PutMapping("/update")
    public Result<Void> updateAnnouncement(@RequestBody Announcement announcement) {
        return announcementService.updateAnnouncement(announcement);
    }

    @DeleteMapping("/{announcementId}")
    public Result<Void> deleteAnnouncement(@PathVariable("announcementId") Integer announcementId) {
        return announcementService.deleteAnnouncement(announcementId);
    }

    @PutMapping("/updateStatus/{announcementId}")
    public Result<Void> updateStatus(@PathVariable("announcementId") Integer announcementId,
                                   @RequestParam("status") String status) {
        return announcementService.updateStatus(announcementId, status);
    }

    @PutMapping("/updateTop/{announcementId}")
    public Result<Void> updateTop(@PathVariable("announcementId") Integer announcementId,
                                @RequestParam("isTop") String isTop) {
        return announcementService.updateTop(announcementId, isTop);
    }

}
